<?xml version='1.0' encoding='UTF-8'?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:finantial="http://java.sun.com/jsf/composite/components/finantial"
      xmlns:composite="http://java.sun.com/jsf/composite"
      xmlns:ui="http://java.sun.com/jsf/facelets">


    <composite:interface shortDescription="renderiza label e input do tipo obrigatório"><!--futuramente colocar decorator - tipo seam:decorate -->

        <composite:attribute  name="id" required="true"  />
        <composite:attribute  name="idToUpdate"/>
        <composite:attribute name="type" required="true" shortDescription="can be income or outcome" />


    </composite:interface>

    <composite:implementation>
        <p:dialog widgetVar="#{cc.attrs.id}" modal="true"  showEffect="explode"  hideEffect="explode"  header="Incluir Tipo de #{cc.attrs.type eq 'income' ? 'Receita':'Despesa'}" >
            <h:form id="type_form#{cc.attrs.id}" prependId="false">
                <p:outputPanel id="type_panel#{cc.attrs.id}">
                    <p:panel>
                        <h:panelGrid id="type_grid#{cc.attrs.id}" columns="2">
                            <finantial:label   value="Descrição:"/>
                            <h:inputText   rendered="#{cc.attrs.type eq 'outcome'}"  value="#{configurationBean.outcomeType.description}"/>
                            <h:inputText   rendered="#{cc.attrs.type eq 'income'}" value="#{configurationBean.incomeType.description}"/>
                        </h:panelGrid>
                        <div align="center">
                            <h:panelGrid columns="2" cellspacing="10">
                                <p:commandButton value="salvar" rendered="#{cc.attrs.type eq 'outcome'}" action="#{configurationBean.addOutcomeType}"  ajax="true" async="true" update="type_msg#{cc.attrs.id} #{cc.attrs.idToUpdate}" oncomplete="handleAddType#{cc.attrs.id}(xhr, status, args)"/>
                                <p:commandButton value="salvar" rendered="#{cc.attrs.type eq 'income'}" action="#{configurationBean.addIncomeType}" ajax="true" async="true" update="type_msg#{cc.attrs.id} #{cc.attrs.idToUpdate}" oncomplete="handleAddType#{cc.attrs.id}(xhr, status, args)"/>
                            </h:panelGrid>
                        </div>
                        <p:messages id="type_msg#{cc.attrs.id}"/>
                    </p:panel>

                </p:outputPanel>
            </h:form>
        </p:dialog>



        <script type="text/javascript">
         function handleAddType#{cc.attrs.id}(xhr, status, args){
             if(! args.failled){
                 setTimeout("waitType#{cc.attrs.id}()",1000);
                 return true;
             }
             return false;
         }

         function waitType#{cc.attrs.id}(){
             #{cc.attrs.id}.hide();
         }

        </script>
    </composite:implementation>



</html>


